home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / grafix / 3d / dust1.84.lha / Dust / crystal / crystal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-25  |  6.4 KB  |  215 lines

  1. /* crystal */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. double ax,ay,az,bx,by,bz,cx,cy,cz;
  7. long dim,i;
  8. char hs[128],name[16],fn[128];
  9. FILE *out;
  10.  
  11. main() {
  12.  printf("\ncrystal V0.4(20 November 1994) - ©1994 by A.Maschke");
  13.  printf("\nname: ");scanf("%s",&name);
  14.  printf("\nax: ");scanf("%s",&hs);ax=strtod(hs,NULL);
  15.  printf("ay: ");scanf("%s",&hs);ay=strtod(hs,NULL);
  16.  printf("az: ");scanf("%s",&hs);az=strtod(hs,NULL);
  17.  printf("\nbx: ");scanf("%s",&hs);bx=strtod(hs,NULL);
  18.  printf("by: ");scanf("%s",&hs);by=strtod(hs,NULL);
  19.  printf("bz: ");scanf("%s",&hs);bz=strtod(hs,NULL);
  20.  printf("\ncx: ");scanf("%s",&hs);cx=strtod(hs,NULL);
  21.  printf("cy: ");scanf("%s",&hs);cy=strtod(hs,NULL);
  22.  printf("cz: ");scanf("%s",&hs);cz=strtod(hs,NULL);
  23.  dim=1;
  24.  printf("\n");
  25.  while(dim<3) {
  26.  printf("dim: ");scanf("%d",&dim);
  27.  }
  28.  strcpy(fn,name);
  29.  strcat(fn,".bat");
  30.  out=fopen(fn,"w");
  31.  if (out!=NULL) {
  32.   /* load objects */
  33.   fprintf(out,"load(1,crystal/atom)");
  34.   fprintf(out,"\nload(2,crystal/bond)");
  35.   /* create bonds */
  36.   fprintf(out,"\ncopy(2,12)");
  37.   fprintf(out,"\ncopy(2,13)");
  38.   fprintf(out,"\ncopy(2,14)");
  39.   fprintf(out,"\nsetpoint(12,3,%f,%f,%f)",ax+2.0379,ay-1.1766,az);
  40.   fprintf(out,"\nsetpoint(12,4,%f,%f,%f)",ax,ay+2.3532,az);
  41.   fprintf(out,"\nsetpoint(12,5,%f,%f,%f)",ax-2.0379,ay-1.1766,az);
  42.   fprintf(out,"\nsetpoint(13,3,%f,%f,%f)",bx+2.0379,by-1.1766,bz);
  43.   fprintf(out,"\nsetpoint(13,4,%f,%f,%f)",bx,by+2.3532,bz);
  44.   fprintf(out,"\nsetpoint(13,5,%f,%f,%f)",bx-2.0379,by-1.1766,bz);
  45.   fprintf(out,"\nsetpoint(14,3,%f,%f,%f)",cx+2.0379,cy-1.1766,cz);
  46.   fprintf(out,"\nsetpoint(14,4,%f,%f,%f)",cx,cy+2.3532,cz);
  47.   fprintf(out,"\nsetpoint(14,5,%f,%f,%f)",cx-2.0379,cy-1.1766,cz);
  48.   fprintf(out,"\nsave(12,vec1)");
  49.   fprintf(out,"\nsave(13,vec2)");
  50.   fprintf(out,"\nsave(14,vec3)");
  51.   fprintf(out,"\nexit");
  52.  
  53.   fprintf(out,"\nload(1,crystal/atom)");
  54.   fprintf(out,"\nload(2,crystal/bond)");
  55.   fprintf(out,"\nload(12,vec1)");
  56.   fprintf(out,"\nload(13,vec2)");
  57.   fprintf(out,"\nload(14,vec3)");
  58.   /* create atoms */
  59.   fprintf(out,"\ncopy(1,3)");
  60.   fprintf(out,"\ncopy(1,4)");
  61.   for(i=2;i<=dim;i++) {
  62.    fprintf(out,"\ntranslate(3,%f,x)",ax);
  63.    fprintf(out,"\ntranslate(3,%f,y)",ay);
  64.    fprintf(out,"\ntranslate(3,%f,z)",az);
  65.    fprintf(out,"\njoin(3,4,5)");
  66.    fprintf(out,"\ncopy(5,4)");
  67.   }
  68.   fprintf(out,"\ncopy(5,3)");
  69.   fprintf(out,"\ncopy(5,4)");
  70.   for(i=2;i<=dim;i++) {
  71.    fprintf(out,"\ntranslate(3,%f,x)",bx);
  72.    fprintf(out,"\ntranslate(3,%f,y)",by);
  73.    fprintf(out,"\ntranslate(3,%f,z)",bz);
  74.    fprintf(out,"\njoin(3,4,5)");
  75.    fprintf(out,"\ncopy(5,4)");
  76.   }
  77.   fprintf(out,"\ncopy(5,3)");
  78.   fprintf(out,"\ncopy(5,4)");
  79.   for(i=2;i<=dim;i++) {
  80.    fprintf(out,"\ntranslate(3,%f,x)",cx);
  81.    fprintf(out,"\ntranslate(3,%f,y)",cy);
  82.    fprintf(out,"\ntranslate(3,%f,z)",cz);
  83.    fprintf(out,"\njoin(3,4,5)");
  84.    fprintf(out,"\ncopy(5,4)");
  85.   }
  86.   fprintf(out,"\ncopy(5,10)");
  87.   fprintf(out,"\nkill(3)");
  88.   fprintf(out,"\nkill(4)");
  89.   fprintf(out,"\nkill(5)");
  90.   /* b1*/
  91.   fprintf(out,"\ncopy(12,1)");
  92.   fprintf(out,"\ncopy(1,3)");
  93.   fprintf(out,"\ncopy(1,4)");
  94.   for(i=3;i<=dim;i++) {
  95.    fprintf(out,"\ntranslate(3,%f,x)",ax);
  96.    fprintf(out,"\ntranslate(3,%f,y)",ay);
  97.    fprintf(out,"\ntranslate(3,%f,z)",az);
  98.    fprintf(out,"\njoin(3,4,5)");
  99.    fprintf(out,"\ncopy(5,4)");
  100.   }
  101.   fprintf(out,"\ncopy(5,3)");
  102.   fprintf(out,"\ncopy(5,4)");
  103.   for(i=2;i<=dim;i++) {
  104.    fprintf(out,"\ntranslate(3,%f,x)",bx);
  105.    fprintf(out,"\ntranslate(3,%f,y)",by);
  106.    fprintf(out,"\ntranslate(3,%f,z)",bz);
  107.    fprintf(out,"\njoin(3,4,5)");
  108.    fprintf(out,"\ncopy(5,4)");
  109.   }
  110.   fprintf(out,"\ncopy(5,3)");
  111.   fprintf(out,"\ncopy(5,4)");
  112.   for(i=2;i<=dim;i++) {
  113.    fprintf(out,"\ntranslate(3,%f,x)",cx);
  114.    fprintf(out,"\ntranslate(3,%f,y)",cy);
  115.    fprintf(out,"\ntranslate(3,%f,z)",cz);
  116.    fprintf(out,"\njoin(3,4,5)");
  117.    fprintf(out,"\ncopy(5,4)");
  118.   }
  119.   fprintf(out,"\ncopy(5,20)");
  120.   fprintf(out,"\nkill(3)");
  121.   fprintf(out,"\nkill(4)");
  122.   fprintf(out,"\nkill(5)");
  123.   /* b2*/
  124.   fprintf(out,"\ncopy(13,1)");
  125.   fprintf(out,"\ncopy(1,3)");
  126.   fprintf(out,"\ncopy(1,4)");
  127.   for(i=2;i<=dim;i++) {
  128.    fprintf(out,"\ntranslate(3,%f,x)",ax);
  129.    fprintf(out,"\ntranslate(3,%f,y)",ay);
  130.    fprintf(out,"\ntranslate(3,%f,z)",az);
  131.    fprintf(out,"\njoin(3,4,5)");
  132.    fprintf(out,"\ncopy(5,4)");
  133.   }
  134.   fprintf(out,"\ncopy(5,3)");
  135.   fprintf(out,"\ncopy(5,4)");
  136.   for(i=3;i<=dim;i++) {
  137.    fprintf(out,"\ntranslate(3,%f,x)",bx);
  138.    fprintf(out,"\ntranslate(3,%f,y)",by);
  139.    fprintf(out,"\ntranslate(3,%f,z)",bz);
  140.    fprintf(out,"\njoin(3,4,5)");
  141.    fprintf(out,"\ncopy(5,4)");
  142.   }
  143.   fprintf(out,"\ncopy(5,3)");
  144.   fprintf(out,"\ncopy(5,4)");
  145.   for(i=2;i<=dim;i++) {
  146.    fprintf(out,"\ntranslate(3,%f,x)",cx);
  147.    fprintf(out,"\ntranslate(3,%f,y)",cy);
  148.    fprintf(out,"\ntranslate(3,%f,z)",cz);
  149.    fprintf(out,"\njoin(3,4,5)");
  150.    fprintf(out,"\ncopy(5,4)");
  151.   }
  152.   fprintf(out,"\ncopy(5,21)");
  153.   fprintf(out,"\nkill(3)");
  154.   fprintf(out,"\nkill(4)");
  155.   fprintf(out,"\nkill(5)");
  156.   /* b3*/
  157.   fprintf(out,"\ncopy(14,1)");
  158.   fprintf(out,"\ncopy(1,3)");
  159.   fprintf(out,"\ncopy(1,4)");
  160.   for(i=2;i<=dim;i++) {
  161.    fprintf(out,"\ntranslate(3,%f,x)",ax);
  162.    fprintf(out,"\ntranslate(3,%f,y)",ay);
  163.    fprintf(out,"\ntranslate(3,%f,z)",az);
  164.    fprintf(out,"\njoin(3,4,5)");
  165.    fprintf(out,"\ncopy(5,4)");
  166.   }
  167.   fprintf(out,"\ncopy(5,3)");
  168.   fprintf(out,"\ncopy(5,4)");
  169.   for(i=2;i<=dim;i++) {
  170.    fprintf(out,"\ntranslate(3,%f,x)",bx);
  171.    fprintf(out,"\ntranslate(3,%f,y)",by);
  172.    fprintf(out,"\ntranslate(3,%f,z)",bz);
  173.    fprintf(out,"\njoin(3,4,5)");
  174.    fprintf(out,"\ncopy(5,4)");
  175.   }
  176.   fprintf(out,"\ncopy(5,3)");
  177.   fprintf(out,"\ncopy(5,4)");
  178.   for(i=3;i<=dim;i++) {
  179.    fprintf(out,"\ntranslate(3,%f,x)",cx);
  180.    fprintf(out,"\ntranslate(3,%f,y)",cy);
  181.    fprintf(out,"\ntranslate(3,%f,z)",cz);
  182.    fprintf(out,"\njoin(3,4,5)");
  183.    fprintf(out,"\ncopy(5,4)");
  184.   }
  185.   fprintf(out,"\ncopy(5,22)");
  186.   fprintf(out,"\nkill(3)");
  187.   fprintf(out,"\nkill(4)");
  188.   fprintf(out,"\nkill(5)"); 
  189.   /*join all*/
  190.   fprintf(out,"\njoin(20,21,23)");
  191.   fprintf(out,"\njoin(22,23,24)");
  192.   fprintf(out,"\ncopy(10,1)");
  193.   fprintf(out,"\ncopy(24,2)");
  194.   fprintf(out,"\nkill(10)");
  195.   fprintf(out,"\nkill(12)");
  196.   fprintf(out,"\nkill(13)");
  197.   fprintf(out,"\nkill(14)");
  198.   fprintf(out,"\nkill(20)");
  199.   fprintf(out,"\nkill(21)");
  200.   fprintf(out,"\nkill(22)");
  201.   fprintf(out,"\nkill(23)");
  202.   fprintf(out,"\nkill(24)");
  203.   
  204.   /*save it */
  205.   fprintf(out,"\njoin(1,2,3)");
  206.   fprintf(out,"\nsave(3,%s.obj)",name);
  207.   fprintf(out,"\n"); 
  208.   fclose(out);
  209.  }
  210.  else {
  211.   printf("\nCouldn't open file.");
  212.  }
  213.  printf("\n");
  214. }
  215.